

const { ccclass, property } = cc._decorator;
import skill from "./enum/skill";
import Boss from "./Boss";
import BossType from "./enum/boss";

@ccclass
export default class SkillPlay extends cc.Component {

    @property(Boss)
    boss: Boss

    @property(cc.AudioClip)
    fireAd: cc.AudioClip

    AudioSource: cc.AudioSource
    anim
    onLoad() {
        this.anim = this.node.getComponent(cc.Animation)
        this.AudioSource = this.node.getComponent(cc.AudioSource)
    }

    start() {
        // 注册
    }

    playAudio(audioClip: cc.AudioClip, isLoop) {
        this.AudioSource.clip = audioClip
        if (isLoop) {
            this.AudioSource.loop = true
        }
        this.AudioSource.play()
    }

    setAni(aniName) {
        let animState = this.anim.play(aniName)
        this.AudioSource.clip = this.fireAd
        this.AudioSource.play()
        animState.on('finished', this.onFinished, this);
    }

    onFinished() {
        cc.tween(this.boss.node)
            .to(0.01, { opacity: 255 })
            .call(() => {
                this.boss.getComponent(cc.Animation)
                this.boss.setAni(BossType.bossDie)
            })
            .start();


    }
    // update (dt) {}
}
